//
//  RegisterImplementations.swift
//  MikerShop
//
//  Created by eme on 2016/11/24.
//  Copyright © 2016年 eme. All rights reserved.
//


import Foundation
import RxSwift
import UtilCore

class RegisterImplementations: RegisterValidationProtocol {
    
    
    /// 手机号 验证
    func validatePhone( _ phone:String)  -> ValidationResult{
        if phone.characters.count == 0 {
            return .empty
        }
        if phone =~ validationRegExp.mobile {
            return .ok(message: "正确")
        }else{
           
            return .failed(message: (UtilCore.alertmsg[100001001]?.msgtitle ?? "手机号不合法")!)
        }
    }
    /// 短信验证码 合法性验证
    func validateMsgCode( _ msgCode:String)  -> ValidationResult{
        if msgCode.characters.count == 0 {
            return .empty
        }
        if msgCode.characters.count == 4 {
            return .ok(message: "正确")
        }else{
            return .failed(message: (UtilCore.alertmsg[100001002]?.msgtitle ?? "短信不合法")!)
        }
    }
    /// 邀请码 合法性验证
    func validateRegisterCode( _ registerCode:String)  -> ValidationResult{
        if registerCode.characters.count == 0 {
            return .ok(message: "不做验证(可为空)")
        }
        if registerCode.characters.count <= 15{
            return .ok(message: "正确")
        }else{
            return .failed(message: (UtilCore.alertmsg[100001003]?.msgtitle ?? "邀请码不合法")!)
        }
    }
    /// 企业名称 合法性验证
    func validateCompanyName( _ companyName:String)  -> ValidationResult{
        if companyName.characters.count == 0 {
            return .empty
        }
        if companyName.characters.count <= 32 {
            return .ok(message: "正确")
        }else{
            return .failed(message: (UtilCore.alertmsg[100001006]?.msgtitle ?? "企业名称不合法")!)
        }
    }
    /// 联系人 合法性验证
    func validateContactName( _ contactName:String)  -> ValidationResult{
        if contactName.characters.count == 0 {
            return .empty
        }
        if contactName.characters.count <= 24 {
            return .ok(message: "正确")
        }else{
            return .failed(message: (UtilCore.alertmsg[100001007]?.msgtitle ?? "联系人不合法")!)
        }
    }
    /// 所在城市 合法性
    func validateCity( _ city:String)  -> ValidationResult{
        if city.characters.count == 0 {
            return .empty
        }
        if city =~ validationRegExp.mobile {
            return .ok(message: "正确")
        }else{
            return .failed(message: (UtilCore.alertmsg[100001008]?.msgtitle ?? "联系地址不合法")!)
        }
    }
    /// 营业执照 合法性验证
    func validateBslicense( _ bslicense:String)  -> ValidationResult{
        if bslicense.characters.count == 0 {
            return .empty
        }
        if bslicense =~ validationRegExp.yingyezhizhao{
            return .ok(message: "正确")
        }else{
            return .failed(message: (UtilCore.alertmsg[100001009]?.msgtitle ?? "营业执照编号不合法")!)
        }
    }
    /// 密码 合法性验证
    func validatePassword( _ password:String)  -> ValidationResult{
        if password.characters.count == 0 {
            return .empty
        }
        if password  =~ validationRegExp.password{
            return .ok(message: "正确")
        }else{
            return .failed(message: (UtilCore.alertmsg[100001004]?.msgtitle ?? "密码不合法")!)
        }
    }
    /// 再次密码 合法性验证
    func validateRepeatPassword( _ password:String,repeatPassword:String)  -> ValidationResult{
        if repeatPassword.characters.count == 0 {
            return .empty
        }
        if password == repeatPassword {
            return .ok(message: "正确")
        }else{
            return .failed(message: (UtilCore.alertmsg[100001005]?.msgtitle ?? "两次输入的密码不一致")!)
        }
    }
}
